package com.itheima.controller;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.itheima.convert.DateConverter;
/**
 * 日期控制器类
 */
@Controller
public class DateController {
//	@Autowired
//	DateConverter d;
	/**
	 * 使用自定义类型数据绑定日期数据
	 */
	@RequestMapping("/customDate")
	public String CustomDate(Date date) {
	    System.out.println("date="+date);
	    return "success";
	}
	
	@RequestMapping("/customDate2")
	public String CustomDate2(Date date,Model model) {
	    System.out.println("date="+date);
		model.addAttribute("datedata",date);
	    return "success_date";
	}
	@RequestMapping("/question")
	public String question(Model model) {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String current=sdf.format(date);
	    model.addAttribute("data",date);
	    return "question";
	}
	
	@RequestMapping("/answer")
	public String answer(HttpServletRequest request,HttpServletResponse response,Model model) throws ParseException {
	    String year=request.getParameter("year");
	    System.out.println(year);
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    Date date=sdf.parse(year);
	    SimpleDateFormat sdf1 = new SimpleDateFormat("EEEE");
	    String week=sdf1.format(date);
		model.addAttribute("datedata",year);
		model.addAttribute("Week", week);
	    return "answer";
	}
}
